﻿using System;
using System.Collections.Generic;
using System.Linq;
using Model.Entity;
using Ones.Dal.Repository.Interfaces;

namespace Ones.Dal.Repository.Impl
{
    public class CommentDao : AbstractDao<Comment>, ICommentDao
    {
        public override Comment
        getById(object id)
        {
            return getSingle(i => i.cmtId.Equals((Guid)id));
        }

        public List<Comment>
        getByNews(int newsId)
        {
            try
            {
                return getMultiple(i => i.newsId == newsId);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByWriterName(string cmtWriter)
        {
            try
            {
                return getMultiple(i => i.cmtWriter.Equals(cmtWriter));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public Comment getByWriterNameExactly(string cmtWriter)
        {
            return getSingle(i => i.cmtWriter.Equals(cmtWriter));
        }

        public List<Comment>
        getByDatePost(DateTime cmtDatePost)
        {
            try
            {
                return getMultiple(i => i.cmtDatePost.Equals(cmtDatePost));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByDatePost(int yyyy, int mm, int dd)
        {
            try
            {
                return getMultiple(i => i.cmtDatePost.Year == yyyy &&
                                        i.cmtDatePost.Month == mm &&
                                        i.cmtDatePost.Day == dd);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByYear(int yyyy)
        {
            try
            {
                return getMultiple(i => i.cmtDatePost.Year == yyyy);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByMonth(int mm)
        {
            try
            {
                return getMultiple(i => i.cmtDatePost.Month == mm);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByDate(int dd)
        {
            try
            {
                return getMultiple(i => i.cmtDatePost.Day == dd);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<Comment>
        getByIllegal(bool cmtIsIllegal)
        {
            try
            {
                return getMultiple(i => i.cmtIsIllegal == cmtIsIllegal);
            }
            catch (Exception)
            {
                return null;
            }
        }
    }

    #region ICommentDao

    public interface ICommentDao : IDao<Comment>
    {
        List<Comment> getByNews(int newsId);

        List<Comment> getByWriterName(String cmtWriter);

        Comment getByWriterNameExactly(String cmtWriter);

        List<Comment> getByDatePost(DateTime cmtDatePost);

        List<Comment> getByDatePost(int yyyy, int mm, int dd);

        List<Comment> getByYear(int yyyy);

        List<Comment> getByMonth(int mm);

        List<Comment> getByDate(int dd);

        List<Comment> getByIllegal(bool cmtIsIllegal);
    }
    #endregion
}